%The Sylvester's criterion.
%
%This function check if the given matrix A is symmetric, definite positive, using the Sylvester's Criterion.
%
%Prototype: bool = sylvester(A)
%
%Input:     The A matrix to check.
%
%Output:    It returns 1 (TRUE) if A is symmetric, definite positive.
%           It returns 0 (FALSE) if A is NOT symmetric, definite positive.
%
%Author: Esposito Gianluca (N.Matr.056/100858)
%Revision Claudio Fantacci, Alessandro Martini.

function bool = sylvester( A )

bool = -1;
[row,col] = size(A);

%Is A a square matrix?
if (row ~= col)
   fprintf('Impossibile proseguire: matrice non quadrata\n');
   return
end

%Is A symmetric?
At = A';
for i = 1 : row
   for j = 1 : col
      if (abs(At(i,j) - A(i,j)) >= eps)
         fprintf('Impossibile proseguire: matrice non simmetrica\n');
         return
      end
   end
end

%The Sylvester's criterion
for k = 1 : row
   if (det(A(1:k,1:k)) <= 0)
      bool = 0;
      return
   end
end
bool = 1;   
